package com.hjm.project.bounty.bounty.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.hjm.project.bounty.bounty.domain.SpecialBounty;
import com.hjm.project.bounty.bounty.service.ISpecialBountyService;
import com.hjm.project.system.dict.domain.DictData;
import com.hjm.project.system.dict.service.IDictDataService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;

import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.common.utils.poi.ExcelUtil;
import com.hjm.framework.web.page.TableDataInfo;

/**
 * 盟主引流特别奖励Controller
 * 
 * @author LOVE
 * @date 2020-11-24
 */
@Controller
@RequestMapping("/bounty/bounty")
public class SpecialBountyController extends BaseController
{
    private String prefix = "bounty/bounty";

    @Autowired
    private ISpecialBountyService specialBountyService;

    @Autowired
    private IDictDataService dictDataService;

    @RequiresPermissions("bounty:bounty:view")
    @GetMapping()
    public String bounty()
    {
        return prefix + "/bounty";
    }

    /**
     * 查询盟主引流特别奖励列表
     */
    @RequiresPermissions("bounty:bounty:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SpecialBounty specialBounty)
    {
        startPage();
        List<SpecialBounty> list = specialBountyService.selectSpecialBountyList(specialBounty);
        return getDataTable(list);
    }

    /**
     * 导出盟主引流特别奖励列表
     */
    @RequiresPermissions("bounty:bounty:export")
    @Log(title = "盟主引流特别奖励", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SpecialBounty specialBounty)
    {
        List<SpecialBounty> list = specialBountyService.selectSpecialBountyList(specialBounty);
        ExcelUtil<SpecialBounty> util = new ExcelUtil<SpecialBounty>(SpecialBounty.class);
        return util.exportExcel(list, "bounty");
    }

    /**
     * 新增盟主引流特别奖励
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        SpecialBounty specialBounty=new SpecialBounty();
        List<SpecialBounty> list = specialBountyService.selectSpecialBountyList(specialBounty);
        Map<String,Object> map=new HashMap<>(16);
        if (list.size()>0) {
            List<DictData> dictDatas = (List<DictData>)dictDataService.selectDictDataByType("special_bounty_gear");
            for (DictData dictData : dictDatas) {
                for (SpecialBounty bounty : list) {
                    if (dictData.getDictValue().equals(String.valueOf(bounty.getGear()))){
                        map.put("id"+dictData.getDictValue(),bounty.getId());
                        map.put("numbers"+dictData.getDictValue(),bounty.getNumbers());
                        map.put("sumMoney"+dictData.getDictValue(),bounty.getSumMoney());
                        map.put("bountyMonthShow"+dictData.getDictValue(),bounty.getBountyMonthShow());
                        map.put("bountyMonthHide"+dictData.getDictValue(),bounty.getBountyMonthHide());
                        map.put("gear"+dictData.getDictValue(),bounty.getGear());
                    }
                }
            }
            mmap.put("flag","1");
        }else{
            mmap.put("flag","0");
        }
        mmap.put("specialBountys",map);
        return prefix + "/add";
    }

    /**
     * 设置盟主引流特别奖励
     */
    @RequiresPermissions("bounty:bounty:add")
    @Log(title = "盟主引流特别奖励", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@RequestParam Map<String,String> params)
    {
        return specialBountyService.insertSpecialBounty(params);
    }

    /**
     * 修改盟主引流特别奖励
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SpecialBounty specialBounty = specialBountyService.selectSpecialBountyById(id);
        mmap.put("specialBounty", specialBounty);
        return prefix + "/edit";
    }

    /**
     * 修改保存盟主引流特别奖励
     */
    @RequiresPermissions("bounty:bounty:edit")
    @Log(title = "盟主引流特别奖励", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SpecialBounty specialBounty)
    {
        return toAjax(specialBountyService.updateSpecialBounty(specialBounty));
    }

    /**
     * 删除盟主引流特别奖励
     */
    @RequiresPermissions("bounty:bounty:remove")
    @Log(title = "盟主引流特别奖励", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(specialBountyService.deleteSpecialBountyByIds(ids));
    }
}
